<template>
	<!--自定义动态tarbar 在需要展示tarbar的页面引入即可
    <tabBar selectedIndex = 0></tabBar>
 
    第一种：
     * 根据身份判断 动态显示tarbar内容
 
    第二种：
     * 有具体的页面传递需要动态显示的tarbar，也是支持的
 
     设计思路：tarbar组件根据页面传递的动态内容显示不同tarbar效果
  -->
	<view class="tab">
		<!--    <image src="/static/images/tabbar/index.png"></image>-->
		<view v-for="(item,index) in list" :key="index" class="tab-item" @click="switchTab(item, index)">
			
			<image class="tab_img" :src="currentIndex == index ? item.selectedIconPath : item.iconPath"></image>
			<view class="tab_text" :style="{color: currentIndex == index ? selectedColor : color}">{{ item.text }}
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "rarbar",
		props: {
			selectedIndex: { // 当前选中的tab index
				default: 0
			},
		},
		data() {
			return {
				color: "#666666",
				selectedColor: "#017c9e",
				list: [],
				currentIndex: 0,
			}
		},
		created() {
			this.currentIndex = this.selectedIndex;

			let _this = this
			/**
			 * 第一种：
			 * 根据身份判断 动态显示tarbar内容
			 * 登录从后端获取值设置值
			 */
			if (uni.getStorageSync('brokerageSet').is_open == 1) {
				//角色1
				_this.list = [{
						"pagePath": "/pages/index/index",
						"text": "首页",
						"iconPath": "/static/tabbar/蒙版.png",
						"selectedIconPath": "/static/tabbar/蒙版-1.png"
					},

					{
						"pagePath": "/pages/activityPgae/activity",
						"text": "活动",
						"iconPath": "/static/tabbar/蒙版-2.png",
						"selectedIconPath": "/static/tabbar/蒙版-3.png"
					},

					{


						"pagePath": "/pages/partnerPromotion/promotionCenter",
						"text": "推广",
						"iconPath": "/static/tabbar/蒙版-6.png",
						"selectedIconPath": "/static/tabbar/蒙版-7.png"
					},

					{
						"pagePath": "/pages/mine/mine",
						"text": "我的",
						"iconPath": "/static/tabbar/蒙版-4.png",
						"selectedIconPath": "/static/tabbar/蒙版-5.png"
					}
				]
			} else {
				//角色2 item.selectedIconPath : item.iconPath"
				_this.list = [[{
						"pagePath": "/pages/index/index",
						"text": "首页",
						"iconPath": "/static/tabbar/蒙版.png",
						"selectedIconPath": "/static/tabbar/蒙版-1.png"
					},

					{
						"pagePath": "/pages/activityPgae/activity",
						"text": "活动",
						"iconPath": "/static/tabbar/蒙版-2.png",
						"selectedIconPath": "/static/tabbar/蒙版-3.png"
					},

					

					{
						"pagePath": "/pages/mine/mine",
						"text": "我的",
						"iconPath": "/static/tabbar/蒙版-4.png",
						"selectedIconPath": "/static/tabbar/蒙版-5.png"
					}
				]
				]
			}

			/**
			 * 第二种：
			 * 有具体的页面传递需要动态显示的tarbar，也是支持的
			 */

		},
		methods: {
			switchTab(item, index) {
				this.currentIndex = index;
				let url = item.pagePath;
				console.log("url", url)

				// 跳转tarbar 使用这种方式
				// this.$tab.switchTab( url)

				// 跳转普通页面使用郑重方式
				this.$sun.navSwitch(url)
				// this.$tab.redirectTo(url)
			}
		}
	}
</script>

<style lang="scss">
	.tab {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		height: 144rpx;
		background: white;
		display: flex;
		justify-content: center;
		align-items: center;
		z-index: 9999;
		    padding-top: 30rpx;
		padding-bottom: env(safe-area-inset-bottom); // 适配iphoneX的底部

		.tab-item {
			flex: 1;
			text-align: center;
			display: flex;
			justify-content: center;
			align-items: center;
			flex-direction: column;

			.tab_img {
				width: 40rpx;
				height: 40rpx;
			}

			.tab_text {
				font-size: 20rpx;
				margin-top: 10rpx;
				margin-bottom: 4rpx;
			}
		}
	}
</style>